package com.baichang.taoshunda.utils;


import com.baichang.taoshunda.service.CouponService;
import com.baichang.taoshunda.service.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * Created by ${wushenglu} on 17/09/08.
 */
public class GetCounponListUtil {
    @Autowired
    private  static CouponService couponService;
    @Autowired
    private static PromotionService promotionService;

    public static List<Map<String, Object>> getCouponList(List<Map<String, Object>> mapList) {
        for (int i = 0; i < mapList.size(); i++) {
            //获取商家编号
            int busId = Integer.parseInt(mapList.get(i).get("id").toString());
            //遍历获取商家的优惠劵
            List<Map<String, Object>> couponList = couponService.getCouponByBussId(busId);
            if (couponList.size() > 0) {
                mapList.get(i).put("couponList", couponList);
            }
            //遍历获取商家的优惠活动
            List<Map<String, Object>> promotionList = promotionService.getPromotionByBussId(busId);
            if (promotionList.size() > 0) {
                mapList.get(i).put("promotionList", promotionList.get(0).get("name"));
            } else {
                mapList.get(i).put("promotionList", "");
            }

        }
        return mapList;
    }
}
